package com.chenfan.mcn.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * 形式合同-下单平台枚举
 *
 * @author wulg
 * @date 2021-08-03
 **/
@AllArgsConstructor
@SuppressWarnings("AlibabaEnumConstantsMustHaveComment")
public enum OrderPlatformEnum {

    /**
     * 形式合同-下单平台枚举
     */
    WEIQ("WEIQ", "WEIQ") {

        @Override
        public boolean meetLength(String platformOrderCode) {
            return StringUtils.length(platformOrderCode) == 16;
        }
    },
    TIKTOKSTARMAP("Tiktokstarmap", "抖音星图") {

        @Override
        public boolean meetLength(String platformOrderCode) {
            return StringUtils.length(platformOrderCode) == 19;
        }

        @Override
        public boolean verifyFormat(String platformOrderCode) {
            return StringUtils.startsWith(platformOrderCode, "7");
        }
    },
    REDBOOK("redbook", "小红书") {

        @Override
        public boolean meetLength(String platformOrderCode) {
            return StringUtils.length(platformOrderCode) == 19;
        }

        @Override
        public boolean verifyFormat(String platformOrderCode) {
            return StringUtils.startsWith(platformOrderCode, "1");
        }
    },
    WEIBO("Weibo", "微博易") {

        @Override
        public boolean meetLength(String platformOrderCode) {
            int length = StringUtils.length(platformOrderCode);
            return length == 7 || length == 20;
        }
    },
    FIREWORKS("Fireworks", "花火") {

        @Override
        public boolean meetLength(String platformOrderCode) {
            return StringUtils.length(platformOrderCode) == 18;
        }
    },
    EMAIL_CONFIRMATION("Email_confirmation", "邮件确认");

    @Getter
    private String code;

    @Getter
    private String desc;

    public static OrderPlatformEnum toEnum(String code) {
        OrderPlatformEnum orderPlatformEnum = null;
        for (OrderPlatformEnum item : OrderPlatformEnum.values()) {
            if (item.getCode().equalsIgnoreCase(code)) {
                orderPlatformEnum = item;
                break;
            }
        }
        return orderPlatformEnum;
    }

    /**
     * 是否满足长度要求
     * @param platformOrderCode
     * @return
     */
    public boolean meetLength(String platformOrderCode) {
        return StringUtils.length(platformOrderCode) <= 50;
    }

    /**
     * 校验格式
     * @param platformOrderCode
     * @return
     */
    public boolean verifyFormat(String platformOrderCode) {
        return true;
    }
}
